<template>
  <div class="table-page-search-wrapper ccslh">
    <a-card>
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="12" :sm="12">
            <a-form-item
                :label="$t('key.sqsj')"
                :labelCol="{span: 4}"
                :wrapperCol="{span: 19, offset: 1}"
            >
              <a-range-picker style="width: 100%" v-model="queryParam.timeArange"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="12">
            <a-form-item
              :label="$t('key.xh')"
              :labelCol="{span: 8}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-input v-model="queryParam.xh"/>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
            <a-col :md="8" :sm="12">
              <a-form-item
                :label="$t('key.name')"
                :labelCol="{span: 8}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-input v-model="queryParam.xm"/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="12">
              <a-form-item :label="$t('key.yx')">
                <a-select allowClear v-model="queryParam.ssyxm" showSearch :filterOption="filterOption">
                  <a-select-option v-for="i in selectMenu.yxList" :key="i.id" :value="i.dwh">{{ i.dwh+'-'+i.dwmc }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="12" :sm="12">
            <span class="table-page-search-submitButtons" >
              <a-button type="primary" @click="$refs.table.refresh(true)" style="margin:0 10px">{{ $t('button.query') }}</a-button>
              <a-button type="primary" @click="batchExport" style="margin:0 10px">{{ $t('button.export') }}</a-button>
              
              <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? $t('button.packUp') : $t('button.advance') }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </a-card>

    <a-card :bordered="false" style="margin-top: 10px">
      <s-table
        class="pratice-result_table"
        v-if="initDone"
        ref="table"
        size="default"
        rowKey="xh"
        :columns="columns"
        :data="loadData"
        :alert="options.alert"
        :rowSelection="options.rowSelection"
        :pageSize="parameter.pageSize"
        :pageNum="parameter.pageNum"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 + (parameter.pageNo - 1) * parameter.pageSize }}
        </span>
        <span slot="pjsqsj" slot-scope="pjsqsj">
          {{ pjsqsj && pjsqsj.slice(0, 10) }}
        </span>
        <span slot="zysjqzsj" slot-scope="text, record">
          {{ record.zysjkssj.slice(0, 10) }} - {{ record.zysjjssj.slice(0, 10) }}
        </span>
        <template slot="id" slot-scope="id">
          <!-- <a v-if="record.shzt == '02'" @click="toDetail(id, 1)">{{ $t('button.audit') }}</a>
          <a-divider type="vertical" /> -->
          <a @click="toDetail(id, 0)">{{ $t('button.view') }}</a>
        </template>
      </s-table>
    </a-card>

  </div>
</template>

<script>
import { STable } from '~'
import { mapState } from 'vuex'
import searchMixin from '@/utils/searchRemain'

export default {
  mixins: [ searchMixin ],
  data () {
    return {
      advanced: true,
      queryParam: {},
      columns: [
        {
          title: this.$t('key.xh'),
          dataIndex: 'xh'
        },
        {
          title: this.$t('key.name'),
          dataIndex: 'xm'
        },
        {
          title: this.$t('key.pydw'),
          dataIndex: 'ssyxmc'
        },
        {
          title: this.$t('key.sqsj'),
          dataIndex: 'pjsqsj',
          width: '150',
          scopedSlots: { customRender: 'pjsqsj' },
        },
        {
          title: this.$t('key.sjdwzdjspj'),
          width: '380',
          dataIndex: 'sjdwzdjspj'
        },
        {
          title: this.$t('key.cjjb'),
          width: '150',
          dataIndex: 'cjmc'
        },
        {
          title: this.$t('key.shzt'),
          width: '180',
          dataIndex: 'shztmc'
        },
        // {
        //   title: this.$t('key.opinion'),
        //   dataIndex: 'lwtm'
        // },
        
        {
          title: this.$t('key.option'),
          dataIndex: 'id',
          scopedSlots: { customRender: 'id' },
          // fixed:'right',
          width:100
        }
      ],
      parameter: {
        pageNo: 1,
        pageSize: 10
      },
      selectedRowKeys: [],
      options: {
        alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
        rowSelection: {
          selectedRowKeys: this.selectedRowKeys,
          onChange: this.onSelectChange
        }
      },
      loadData: parameter => {
        this.parameter = parameter
        parameter.pageNum = parameter.pageNo
        let params = Object.assign({},parameter, this.queryParam)
        if (params.timeArange && params.timeArange.length) {
          params.zysjkssj = params.timeArange[0].format('YYYY-MM-DD')
          params.zysjjssj = params.timeArange[1].format('YYYY-MM-DD')
          delete params.timeArange
        }
        return this.$api.degree.zysjjgpjPassList(params).then(res => {
          res.data.rows.map(item=>{
            item.shztmc = item.shzt == '07' ? '专业学位办已备案' : (item.shzt == '08' ? '专业学位办未备案':item.shztmc)
          })
          return {
            data: res.data.rows,
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize,
            totalPage: Math.ceil(res.data.total / parameter.pageSize),
            totalCount: res.data.total
          }
        })
      },
      selectMenu: {},
      visible: false,
      checkId: '',
      initDone: false
    }
  },
  components: {STable},
  computed: {
    ...mapState({
    })
  },
  created () {
    // this.initSelectMenu()
  },
  activated() {
    this.doRefresh()
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yxList: res[0].data
        }
        this.initDone = true
      })
    },
    filterOption (value, op) {
      return op.componentOptions.children[0].text.indexOf(value) !== -1
    },
    yxChange (code) {
      this.$set(this.queryParam, 'zyh', '')
      if (code) {
        this.$api.base.majorAll({lsdwh: code}).then(res => {
          this.$set(this.selectMenu, 'zyList', res.data)
        })
      } else {
        this.$set(this.selectMenu, 'zyList', [])
      }
    },
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
    },
    showBatchCheck() {
      if (!this.selectedRowKeys.length) {
        return this.$message.warn('请选择要审核的论文')
      }
      this.checkId = this.selectedRowKeys.join(',')
      this.visible = true
      this.$nextTick(() => {
        this.$refs.check.form.resetFields()
      })
    },
    toDetail(id, isCheck) {
      this.$router.push(`/degree/practiceResult/detail?id=${id}&isCheck=${isCheck}`)
    },
    checkPaper(params) {
      this.$api.degree.paperCheck(params).then(res => {
        this.visible = false
        this.$message.success(res.msg)
        this.doRefresh()
      })
    },
    doRefresh(){
      this.$refs.table.refresh(false)
    },
    batchExport(){
      if (!this.selectedRowKeys.length) {
        return this.$message.warn('请选择要导出的实践结果评价')
      }
      this.$export('/teacherClient/zysjjgpj/batchExpZysj', {
        xhs: this.selectedRowKeys.join(',')
      })
      // let params = {...this.queryParam}
      // delete params.pageNum
      // delete params.pageSize
      // this.$export('/teacherClient/zysjjgpj/zysjExpList',params)
    }
  }
}
</script>

<style lang="less">
.ccslh{
  .pratice-result_table{
    table{
      table-layout:fixed;
    }
    tr td:nth-child(6){
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
}

</style>
